﻿# CMakeList.txt: libcpps 的 CMake 项目，在此处包括源代码并定义
# 项目特定的逻辑。
#
cmake_minimum_required (VERSION 3.5)

# 将源代码添加到此项目的可执行文件。
AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/src  SRC_LIST)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include .)

file(GLOB_RECURSE CURRENT_HEADERS  ${PROJECT_SOURCE_DIR}/include/*.h)
source_group("Include" FILES ${CURRENT_HEADERS}) 

IF (WINDOWS)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/lib)


set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/lib)

# msvcpch.cmake的路径
set(MSVCCMAKE_PCH ${PROJECT_SOURCE_DIR}/)
# 预编译头文件和源文件的路径
set(STDAFX_PCH_H ${PROJECT_SOURCE_DIR}/include/cpps/cpps.h)
set(STDAFX_PCH_C ${PROJECT_SOURCE_DIR}/src/libcpps.cpp)	

# 添加预编译cmake的路径
LIST(APPEND CMAKE_MODULE_PATH ${MSVCCMAKE_PCH})
# 包含msvcpch.cmake
INCLUDE(msvcpch)

ELSE ()

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)

ENDIF ()


IF (WINDOWS)
	ADD_LIBRARY (libcpps STATIC ${SRC_LIST} ${CURRENT_HEADERS})
	USE_MSVC_PCH(libcpps cpps/cpps.h ${STDAFX_PCH_C})
ELSEIF (LINUX)
	ADD_LIBRARY (libcpps STATIC ${SRC_LIST} ${CURRENT_HEADERS})
	target_link_libraries(libcpps -lrt -ldl -lm -lpthread)
		
	install(FILES ${CURRENT_HEADERS} DESTINATION include/cpps)

	install(TARGETS libcpps
	RUNTIME DESTINATION bin
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib)

ELSEIF(MACOS)
	ADD_LIBRARY (libcpps STATIC ${SRC_LIST} ${CURRENT_HEADERS})
	target_link_libraries(libcpps -ldl -lm -lpthread)
		
	install(FILES ${CURRENT_HEADERS} DESTINATION include/cpps)

	install(TARGETS libcpps
	RUNTIME DESTINATION bin
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib)
ENDIF ()
